<?php
	if (!session_start()) session_start();
	if (!isset($_SESSION['kiemtradangnhapthinguyet']) || $_SESSION['kiemtradangnhapthinguyet']!=1) {
		header('location: ../../../index.php');
		die();
	}
	$table = "tin";
	$id = $_GET['id'];
	if (isset($_POST["id"]) && $_POST["id"]!="")
		$id = $_POST['id'];
	$record = $class_tin->get_by_thutu($id);
	$thutu = $record["thutu"]; 
	$ngay = $record["ngay"];
	
	$check_isset = array(
		'id',
		'ten_vi',
		'gia_vi',
		'tomtat_vi',
		'noidung_ct_vi',
		'noidung_gia_vi',
		'noidung_dk_vi',
		'noidung_lh_vi',
		'ten_en',
		'gia_en',
		'tomtat_en',
		'noidung_ct_en',
		'noidung_gia_en',
		'noidung_dk_en',
		'noidung_lh_en',
		'id_root',
		'idtl',
		'idloai',
		'url_img',
		'noidung_img',
		'anhien'
	);
	$check_empty = array(
		'id',
		'ten_vi',
		'ten_en'
	); 
	if ($db->check_isset($check_isset)) {
		if ($db->check_empty($check_empty)) {
			$record = new tin;
			$record->dt_set_id($id);
			$record->dt_set_ten_vi($_POST["ten_vi"]);
			$record->dt_set_gia_vi($_POST["gia_vi"]);
			$record->dt_set_tomtat_vi($_POST["tomtat_vi"]);
			$record->dt_set_noidung_ct_vi($_POST["noidung_ct_vi"]);
			$record->dt_set_noidung_gia_vi($_POST["noidung_gia_vi"]);
			$record->dt_set_noidung_dk_vi($_POST["noidung_dk_vi"]);
			$record->dt_set_noidung_lh_vi($_POST["noidung_lh_vi"]);
			$record->dt_set_ten_en($_POST["ten_en"]);
			$record->dt_set_gia_en($_POST["gia_en"]);
			$record->dt_set_tomtat_en($_POST["tomtat_en"]);
			$record->dt_set_noidung_ct_en($_POST["noidung_ct_en"]);
			$record->dt_set_noidung_gia_en($_POST["noidung_gia_en"]);
			$record->dt_set_noidung_dk_en($_POST["noidung_dk_en"]);
			$record->dt_set_noidung_lh_en($_POST["noidung_lh_en"]);
			$record->dt_set_id_root($_POST["id_root"]);
			$record->dt_set_idtl($_POST["idtl"]);
			$record->dt_set_idloai($_POST["idloai"]);
			$record->dt_set_url_img($_POST["url_img"]);
			$record->dt_set_noidung_img($_POST["noidung_img"]);
			$record->dt_set_thutu($thutu);
			$record->dt_set_ngay($ngay);
			$record->dt_set_anhien($_POST["anhien"]);
			
			$record->update();
			?>
				<script language="javascript">alert("Sửa dữ liệu thành công!");</script>
			<?php
			location('index.php?p='.$table.'_quanly');
		}else {
			?>
				<script language="javascript">alert("Not enough information!");</script>
			<?php
		}
	}

?>			
<script type="text/javascript">
function isTest() {
	if (document.getElementById("ten_vi").value=="") {
		alert("You have not entered enough information.");
		return false;
	}
	if (document.getElementById("ten_en").value=="") {
		alert("You have not entered enough information.");
		return false;
	}
	
    return true;
}	
</script>	
            	<div class="dangnhap_title">
                <a href="index.php" style="color:#F8991D;" title="Trang chủ">Trang chủ</a>
                <span style="font-size:9px;">>></span> 
                Tin tức
                <span style="font-size:9px;">>></span> 
                <a href="index.php?p=<?php echo $table; ?>_quanly" style="color:#F8991D;">Tin</a> 
            	</div>
            	<form method="post" action="index.php?p=<?php echo $table; ?>_sua" onSubmit="return isTest();">
            	<input type="hidden" name="id" value="<?php echo $id; ?>" />
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
                        Vietnamese's Information
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Tên(*)
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="ten_vi" id="ten_vi" style="width:520px; padding:0px;" value="<?php echo $record['ten_vi']; ?>" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Giá:
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="gia_vi" style="width:520px; padding:0px;"value="<?php echo $record['gia_vi']; ?>" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Tóm tắt:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="tomtat_vi" name="tomtat_vi" rows="4" cols="30"><?php echo $record['tomtat_vi']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'tomtat_vi',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Nội dung ct:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_ct_vi" name="noidung_ct_vi" rows="4" cols="30"><?php echo $record['noidung_ct_vi']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_ct_vi',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Nội dung giá:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_gia_vi" name="noidung_gia_vi" rows="4" cols="30"><?php echo $record['noidung_gia_vi']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_gia_vi',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Nội dung dk:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_dk_vi" name="noidung_dk_vi" rows="4" cols="30"><?php echo $record['noidung_dk_vi']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_dk_vi',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Nội dung lh:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_lh_vi" name="noidung_lh_vi" rows="4" cols="30"><?php echo $record['noidung_lh_vi']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_lh_vi',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
                        English's Information
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Name(*)
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="ten_en" id="ten_en" style="width:520px; padding:0px;" value="<?php echo $record['ten_en']; ?>" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Price:
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="gia_en" style="width:520px; padding:0px;" value="<?php echo $record['gia_en']; ?>" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Summary:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="tomtat_en" name="tomtat_en" rows="4" cols="30"><?php echo $record['tomtat_en']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'tomtat_en',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- ct Content:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_ct_en" name="noidung_ct_en" rows="4" cols="30"><?php echo $record['noidung_ct_en']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_ct_en',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Price Content:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_gia_en" name="noidung_gia_en" rows="4" cols="30"><?php echo $record['noidung_gia_en']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_gia_en',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- dk Content:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_dk_en" name="noidung_dk_en" rows="4" cols="30"><?php echo $record['noidung_dk_en']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_dk_en',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- lh Content:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_lh_en" name="noidung_lh_en" rows="4" cols="30"><?php echo $record['noidung_lh_en']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_lh_en',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
                        More Information
                    </div>
                </div>
                <script>
					function gettheloaitin() {
						var id = document.getElementById("id_root").value;
						$("#idtl").load("librarys/incs/gettheloaitin.php?id_root="+id);
						$("#idloai").load("librarys/incs/getloaitin.php?idtl=0");
					}
					function getloaitin() {
						var id = document.getElementById("idtl").value;
						$("#idloai").load("librarys/incs/getloaitin.php?idtl="+id);
					}
				</script>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Tin root:
                    </div>
                    <div class="dangnhap_col_input">
                    	<select name="id_root" id="id_root" onchange="gettheloaitin()">
                    		<?php 
                    			$idparent = 0;
                    			$list_tin_root = $class_tin_root->get_by_thutu();
                    			foreach ($list_tin_root as $row) {
                    				if ($record['id_root']==$row['id']) $idparent=$row['id'];
                    				if ($idparent==0) $idparent=$row['id'];
                    		?>
                    		<option value="<?php echo $row['id']; ?>"
                    			<?php if ($record['id_root']==$row['id']) echo "selected='selected'"; ?> >
                    		<?php echo $row['ten_vi']; ?></option>
                    		<?php 
                    			}
                    		?>
                    	</select>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Tin thể loại:
                    </div>
                    <div class="dangnhap_col_input">
                    	<select name="idtl" id="idtl" onchange="getloaitin()">
                    		<option value="0"> - - Chọn thể loại - - </option>
                    		<?php 
                    			$idparent2 = 0;
                    			$list_tin_theloai = $class_tin_theloai->get_by_parent("tin_root", "id_root", $idparent);
                    			foreach ($list_tin_theloai as $row) {
                    				if ($record['idtl']==$row['id']) $idparent2=$row['id'];
                    		?>
                    		<option value="<?php echo $row['id']; ?>"
                    			<?php if ($record['idtl']==$row['id']) echo "selected='selected'"; ?> ><?php echo $row['ten_vi']; ?></option>
                    		<?php 
                    			}
                    		?>
                    	</select>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Tin loại:
                    </div>
                    <div class="dangnhap_col_input">
                    	<select name="idloai" id="idloai">
                    		<option value="0"> - - Chọn loại - - </option>
                    		<?php 
                    			$list_tin_loai = $class_tin_loai->get_by_parent("tin_theloai", "idtl", $idparent2);
                    			foreach ($list_tin_loai as $row) {
                    		?>
                    		<option value="<?php echo $row['id']; ?>"
                    			<?php if ($record['idloai']==$row['id']) echo "selected='selected'"; ?> ><?php echo $row['ten_vi']; ?></option>
                    		<?php 
                    			}
                    		?>
                    	</select>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Images:
                    </div>
                    <div class="dangnhap_col_input">
                        <input id="url_img" type="text" name="url_img" style="width:490px; padding:0px;" value="<?php echo $record['url_img']; ?>" />
                    	<input onclick="BrowseServer('Images:/','url_img')" type="button" name="btnChonFile" id="btnChonFile" value="...." />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="width:710px; padding-bottom:3px;">
                        &nbsp; &nbsp; &nbsp;- Images Content:
                    </div>
                    <div class="dangnhap_col_input" style="width:700px; padding-left:15px;">
                        <textarea id="noidung_img" name="noidung_img" rows="4" cols="30"><?php echo $record['noidung_img']; ?></textarea>
                    	<script type="text/javascript">
						var editor = CKEDITOR.replace( 'noidung_img',{
							uiColor : '#9AB8F3',
							language:'vi',
							skin:'office2003',
							//width:'200',
							filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
							filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
						});
						</script>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Hidden or Show:
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="radio" name="anhien" value="1" <?php if ($record['anhien']==1) echo "checked='checked'"; ?> />Show
                     	<input type="radio" name="anhien" value="0" <?php if ($record['anhien']==0) echo "checked='checked'"; ?> />Hidden
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_input">
                        <input type="image" src="imgs/save_button.png" border="0" />
                        <a href="javascript:history.go(-1);"><img src="imgs/exit_button.png" border="0" /></a>
                    </div>
                </div>
               	</form>